package com.fengye.algorithms.leecode;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author fengye
 * @Date 2023/4/10 9:17
 **/
public class FirstUniqChar387 {
    public int firstUniqChar(String s) {
        Map<Character, Integer> maps = new HashMap<>();

        for (int i = 0; i < s.length();i++) {
            char c = s.charAt(i);
            maps.put(c, maps.getOrDefault(c, 0)+1);
        }

        for(int i=0;i<s.length();i++) {
            int sum = maps.get(s.charAt(i));
            if(sum == 1) {
                return i;
            }
        }

        return -1;
    }
}
